package com.gwm.order.controller;

import com.gwm.order.dto.OrderDTO;
import com.gwm.order.service.OrderService;
import com.gwm.order.service.TbOrderService;
import com.gwm.order.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;

//    TODO
    /**
     * 创建订单
     * @param orderDTO
     * @return
     */
    @PostMapping
    public ResponseEntity<Long> createOrder(@RequestBody OrderDTO orderDTO) {
        Long orderId = this.orderService.createOrder(orderDTO);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).body(orderId);
    }

    /**
     * 查询订单信息
     * @param orderId
     * @return
     */
    @GetMapping("{id}")
    public ResponseEntity<OrderVO> findOrderById(@PathVariable("id") Long orderId){
        return ResponseEntity.ok(orderService.findOrderById(orderId));
    }
//       TODO
    /**
     * 查询秒杀订单
     *
     * @param orderId
     * @return
     */
    @GetMapping("/findOrder")
    public ResponseEntity<OrderVO> findOrder(@RequestParam(name = "id",required = false) Long orderId) {
        return ResponseEntity.ok(orderService.findOrderByOrderId(orderId));
    }


    //todo
//    @GetMapping("url/{id}")
//    public ResponseEntity<String> getPayUrl(@PathVariable("id") Long orderId) {
//        return ResponseEntity.ok(orderService.createPayUrl(orderId));
//    }
//


    //todo
//    /**
//     * 查询支付状态
//     */
//    @GetMapping("/state/{id}")
//    public ResponseEntity<Integer> queryPayState(@PathVariable("id") Long orderId) {
//        return ResponseEntity.ok(orderService.queryPayStatus(orderId.toString()));
//    }


}